<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Actpresellnum_model extends CI_Model {
	
	function __construct(){
        parent::__construct();
    }
    
    function insert($data){
    	$this->db->insert('rsh_act_presell_num', $data);
    	$num = $this->db->insert_id();
		return $num;
    }
    
	function update($id, $data = array()){
		$this->mycache->delete('actpresell_obj_'.$id);
		$this->db->where('id', $id);
		$this->db->update('rsh_act_presell_num', $data);
		return $this->db->affected_rows();
	}
	
	function get_actpresell_obj($id){
		$mkey = "actpresell_obj_".$id;
		$ret = $this->mycache->get_array($mkey);
		if($ret != false){
			return $ret;
		}
		$select = " id,phone,realname,presell_num,add_time,use_time,lose_time,addip,fstatus ";
		$this->db->select($select);
		$this->db->where(array('id'=>$id));
		$query = $this->db->get('rsh_act_presell_num');
		$retsult = $query->row_array();
		$this->mycache->set_array($mkey,$retsult);
		return $retsult;
	}
	
	
	function get_num_by_phone($phone){
		$mkey = "actpresell_obj_".$phone;
		$ret = $this->mycache->get_array($mkey);
		if($ret != false){
			return $ret;
		}
		$select = " presell_num ";
		$this->db->select($select);
		$this->db->where(array('phone'=>$phone));
		$query = $this->db->get('rsh_act_presell_num');
		$retsult = $query->row_array();
		$this->mycache->set_array($mkey,$retsult);
		return $retsult;;
	}
	
}